package drive.Service.ServiceFormat;

import com.google.gson.Gson;
import drive.Mapper.TransactionOrderMapper;
import drive.Model.TransactionOrder;
import drive.Service.ServiceInterface.TransactionOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TransactionOrderServiceA implements TransactionOrderService {
    @Autowired
    private TransactionOrderMapper transactionOrderMapper;

    private Gson gson = new Gson();

    @Override
    public String findAll() {
        List<TransactionOrder> list = transactionOrderMapper.findAll();
        return gson.toJson(list);
    }

    @Override
    public String findByOrderID(int orderID) {
        TransactionOrder order = transactionOrderMapper.findByOrderID(orderID);
        return gson.toJson(order);
    }

    @Override
    public String findByBuyerID(int buyerID) {
        List<TransactionOrder> list = transactionOrderMapper.findByBuyerID(buyerID);
        return gson.toJson(list);
    }

    @Override
    public String findBySellerID(int sellerID) {
        List<TransactionOrder> list = transactionOrderMapper.findBySellerID(sellerID);
        return gson.toJson(list);
    }

    @Override
    public String findByItemID(int itemID) {
        TransactionOrder order = transactionOrderMapper.findByItemID(itemID);
        return gson.toJson(order);
    }

    @Override
    public String add(TransactionOrder order) {
        int result = transactionOrderMapper.add(order);
        return "订单已生成";
    }

    @Override
    public String update(TransactionOrder order) {
        int result = transactionOrderMapper.update(order);
        return "修改订单信息成功";
    }

    @Override
    public String delete(int orderID) {
        int result = transactionOrderMapper.delete(orderID);
        return "订单已删除";
    }
}